package exe4;

import java.util.ArrayList;
import java.util.List;

public class HR {

	List<Employee> employees;
	
	public HR() {
		employees = new ArrayList<Employee>(20);
	}
	
	public List<Employee> getEmployees() {
		return employees;
	}

	public Employee getTopSalaryEmployee() {
		Employee TopSalaryEmployee = employees.get(0);
		for (int i = 0; i < employees.size(); i++) {
			if (employees.get(i).getSalary() > TopSalaryEmployee.getSalary()) {
				TopSalaryEmployee = employees.get(i);
			}
		}
		return TopSalaryEmployee;
	}
	
	public Employee[] getTop10SalaryEmployees() {
		Employee[] Top10SalaryEmployees = new Employee[10];
		for (int i = 0; i < employees.size(); i++) {
			for (int j = 0; j < employees.size() - 1 - i; j++) {
				if (employees.get(j).getSalary() < employees.get(j + 1).getSalary()) {
					Employee temp = employees.get(j);
					employees.set(j, employees.get(j + 1));
					employees.set(j + 1, temp);
				}
			}
		}
		for (int i = 0; i < 10; i++) {
			Top10SalaryEmployees[i] = employees.get(i);
		}
		return Top10SalaryEmployees;
	}
	
	public void enrollEmployee(Employee newEmployee) {
		employees.add(newEmployee);
	}
	
	public void resignEmployee(String employeeID) {
		int index = -1;
		for (int i = 0; i < employees.size(); i++) {
			if (employees.get(i).getId().equals(employeeID)) {
				index = i;
			}
		}
		employees.remove(index);
	}
	
	public boolean isOurEmployee(Employee employee) {
		for (int i = 0; i < employees.size(); i++) {
			if (employees.get(i).equals(employee)) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
